import { defaHttp, ApiRes } from "../index";

/**获取币种列表 */
export async function apiCoinList(): Promise<void | CoinList.ResItem[]> {
  const res = await defaHttp.post<ApiRes<CoinList.ResItem[]>>("/coins");
  if (res.code !== 200) return;
  return res.data;
}
/**获取币种列表 */
export namespace CoinList {
  export interface ResItem extends CoinPay {
    /**
     * 示例：USDT
     */
    code: string;
    /**
     * 示例：18
     */
    format: number;
    /**
     * 示例：1
     */
    id: number;
    /**
     * 示例：https:///images/USDT.png
     */
    logo: string;
  }
}

/**获取游戏余额 */
export async function apiCoinGameBalance(
  data: CoinGameBalance.Req
): Promise<void | CoinGameBalance.Res> {
  const res = await defaHttp.post<ApiRes<CoinGameBalance.Res>>(
    "/wallet/get_balance",
    data
  );
  if (res.code !== 200) return;
  return res.data;
}
/**获取游戏余额 */
export namespace CoinGameBalance {
  export interface Req {
    coin_id: StrNumber;
  }
  export interface Res {
    /**
     * 示例：80.0030
     */
    /**游戏余额 */
    availbale: string;
    /**
     * 示例：0
     */
    could: number;
  }
}

/**获取提币信息 */
export async function apiWithdrawalInfo(): Promise<void | WithdrawalInfo.Res> {
  // data: WithdrawalInfo.Req
  const res = await defaHttp.post<ApiRes<WithdrawalInfo.Res>>(
    "/money/index"
    // data
  );
  if (res.code !== 200) return;
  return res.data;
}
/**获取提币信息 */
export namespace WithdrawalInfo {
  // export interface Req {
  //   coin_id: StrNumber;
  // }
  export interface Res {
    /**
     * 可用金额，示例：0
     */
    available: number;
    /**
     * 示例：-
     */
    coin: Coin;
  }

  /**
   * 示例：-
   */
  export interface Coin {
    /**
     * 示例：0x9Fb5390d000cEa89191ba16Be5Ba16D49db6DB2b
     */
    contract_addr: string;
    /**
     * 示例：18
     */
    decimal: number;
    /**
     * 示例：2
     */
    id: number;
    /**
     * 1：开启提币；0：禁止提币
     */
    is_withdraw: number;
    /**
     * 最低提币数量，示例：1.0000
     */
    min_withdraw: string;
    /**
     * 币价格，示例：0.01125693
     */
    price: string;
    /**
     * 提币手续费。用U来做单位，
     */
    withdraw_fee: string;
  }
}

/**申请提币 */
export async function apiWithdrawCoin(
  data: WithdrawCoin.Req
): Promise<boolean> {
  const res = await defaHttp.post<ApiRes<WithdrawCoin.Res>>(
    "/wallet/withdraw",
    data,
    { mode: { failMessage: true, successMessage: true } }
  );
  if (res.code !== 200) return false;
  return true;
}
/**申请提币 */
export namespace WithdrawCoin {
  export interface Req {
    /**数量 */
    number: number;
    /**币种id */
    coin_id: StrNumber;
  }
  export type Res = void;
}
